home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / clib / malloc.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  1KB  |  76 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: malloc.c,v 1.2 1996/10/23 14:13:41 aros Exp $
  4.  
  5.     Desc: ANSI C function malloc()
  6.     Lang: english
  7. */
  8. #include <exec/memory.h>
  9. #include <clib/exec_protos.h>
  10. extern APTR __startup_mempool;
  11.  
  12. /*****************************************************************************
  13.  
  14.     NAME */
  15.     #include <sys/types.h>
  16.     #include <memory.h>
  17.  
  18.     void * malloc (
  19.  
  20. /*  SYNOPSIS */
  21.     size_t size)
  22.  
  23. /*  FUNCTION
  24.     Allocate size bytes of memory and return the address of the
  25.     first byte.
  26.  
  27.     INPUTS
  28.     size - How much memory to allocate.
  29.  
  30.     RESULT
  31.     A pointer to the allocated memory or NULL. If you don't need the
  32.     memory anymore, you can pass this pointer to free(). If you don't,
  33.     the memory will be freed for you when the application exits.
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.     free()
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     24-12-95    digulla created
  48.  
  49. ******************************************************************************/
  50. {
  51.     UBYTE * mem;
  52.  
  53.     /* Check if there is a pool already */
  54.     if (!__startup_mempool)
  55.     {
  56.     /* Create one if not */
  57.     __startup_mempool = CreatePool (MEMF_ANY, 4096L, 2000L);
  58.  
  59.     /* Fail if the pool could not be created */
  60.     if (!__startup_mempool)
  61.         return NULL;
  62.     }
  63.  
  64.     /* Allocate the memory */
  65.     mem = AllocPooled (__startup_mempool, AROS_ALIGN(sizeof(size_t)) + size);
  66.  
  67.     if (mem)
  68.     {
  69.     *((size_t *)mem) = size;
  70.     mem += AROS_ALIGN(sizeof(size_t));
  71.     }
  72.  
  73.     return mem;
  74. } /* malloc */
  75.  
  76.